package com.lai.hospital.handler;

import com.alibaba.fastjson2.JSON;
import com.lai.hospital.vo.Result;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

import static com.lai.hospital.constant.CommonConst.APPLICATION_JSON;
import static com.lai.hospital.constant.SecurityConst.LOGOUT_SUCCESS;

/**
 * @author : lai
 * @version V1.0
 * @Project: hospital-springboot
 * @Package com.lai.hospital.handler
 * @Description: 退出成功处理器
 * @date Date : 2022年11月18日 14:35
 */
@Component
public class LogoutSuccessHandlerImpl implements LogoutSuccessHandler {
    @Override
    public void onLogoutSuccess(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Authentication authentication) throws IOException, ServletException {
        httpServletResponse.setContentType(APPLICATION_JSON);
        httpServletResponse.getWriter().write(JSON.toJSONString(Result.ok(LOGOUT_SUCCESS)));
    }
}
